﻿using AutoMapper;
using HamcoWcs.Contract.ContractCommon;
using HamcoWcs.DAL;
using HamcoWcs.Entitys.MesMsgQueues;
using HamcoWcs.Models.Common.Enums;
using HamcoWcs.Models.TibcoMessage;
using System;
using System.Xml;

namespace HamcoWcs.Service.Mes.Parsers
{
    /// <summary>
    /// MES获取托盘信息
    /// </summary>
    public class MesMsgParser_GetInventoryZoneDataRequest : MesMsgParserBase
    {
        public override void HandleEvent(MesMsgQueue message)
        {
            GetInventoryZoneDataMessage msg;
            try
            {
                msg = XmlHelper.Deserialize<GetInventoryZoneDataMessage>(message.Content);
                if (msg == null) throw new Exception();
            }
            catch (Exception ex)
            {
                throw new Exception("MesMsgParser->GetInventoryZoneDataRequest:解析失败" + ex.Message);
            }

            var zones = _locationService.InventoryZones();
            msg.Body.ZoneList = new ZoneList(zones);
            msg.SetReplyName();
            message.Return = XmlHelper.Serialize(msg);
            message.Status = (int)EnumMesMsgStatus.WcsExcuted;
        }


        private readonly ILocationService _locationService;
        public MesMsgParser_GetInventoryZoneDataRequest(ILoggerService loggerService, WcsDbContext wcsDbContext, IMapper mapper, ILocationService locationService) : base(loggerService, wcsDbContext, mapper)
        {
            _locationService = locationService;
        }

        public override string EventName => "GetInventoryZoneDataRequest";

    }
}
